package com.wyq.new_springboot.config;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author weiyaqiang
 * @create 2021/4/9 11:30
 */
@Configuration
public class WebMvcConfig  implements WebMvcConfigurer {
    // 分页插件
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }
    //解决在拦截器中不能注入的问题
    @Bean
    public MyInterceptor myInterceptor(){
        return new MyInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(myInterceptor()).addPathPatterns("/**").
                excludePathPatterns(
                        "/test/login",
                        "/test/register",
                        "/test/doRegister",
                        "/test/userLogin",
                        "/static/**");
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        WebMvcConfigurer.super.addViewControllers(registry);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        //registry.addResourceHandler("/css/**","/js/**").addResourceLocations("classpath:/static/css/","classpath:/static/js/");
        //registry.addResourceHandler("/static/js/**").addResourceLocations("classpath:/static/js/");
        //下面的这种写法，页面引入的时候前缀需要加上static，addResourceHandler只是一个逻辑的地址，不是实际地址，addResourceLocations表示要放开的资源

        //添加上传图片的路径
        //registry.addResourceHandler("/static/file/**").addResourceLocations("file:///C:/file");

    }
}
